package com.bafa.front.presentationbeans;

import com.bafa.debug.Debug;
import com.bafa.objects.player.Player;
import com.bafa.objects.player.PlayerDivision;
import com.bafa.objects.player.PlayerMatch;
import com.bafa.objects.player.PlayerSeason;
import com.bafa.objects.player.PlayerTeam;

public class PlayerBean implements Comparable{

	
	private String name;
	private int goals;
	
	/**
	 * This constructor will say how many goals this player has scored in this season.
	 * @param player
	 * @param seasonId
	 * @param divisionId
	 */
	public PlayerBean(Player player,int seasonId, int divisionId) {
		name = player.getFirstname();
		PlayerSeason season = (PlayerSeason)player.getSeasonGoals().get(seasonId);
		PlayerDivision division = (PlayerDivision)season.getDivisionGoals().get(divisionId);
		
		goals=division.getGoals();
		
	}
	
	/**
	 * This constructor will say how many goals this player has scored in this season.
	 * @param player
	 * @param seasonId
	 * @param divisionId
	 */
	public PlayerBean(Player player,int seasonId, int teamId,boolean teamGoals) {
		Debug.debug(this.getClass(),"PlayerBean","Player "+player);
		name = player.getFirstname();
		
		PlayerSeason season = (PlayerSeason)player.getSeasonGoals().get(seasonId);
		Debug.debug(this.getClass(),"PlayerBean","Season "+season);
		PlayerTeam team = (PlayerTeam)season.getTeamGoals().get(teamId);
		Debug.debug(this.getClass(),"PlayerBean","team "+team);
		
		goals=team.getGoals();
		
	}
	
	/**
	 * goals player has scored for team
	 * @param player
	 * @param teamId
	 */
	public PlayerBean(Player player,int teamId) {
		name = player.getFirstname();
		goals=((PlayerTeam)player.getTeamGoals().get(teamId)).getGoals();
		
	}
	public PlayerBean(Player player) {
		name = player.getFirstname();
		
		
	}
	
	public PlayerBean(PlayerMatch match, String name){
		this.name = name;
		goals = match.getGoals();
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getGoals() {
		return goals;
	}
	public void setGoals(int scorer) {
		this.goals = scorer;
	}
	public int compareTo(Object bean) {
		
		if(((PlayerBean)bean).getGoals()!=this.goals)
			return ((PlayerBean)bean).getGoals()-this.goals;
		else{
			return this.name.compareToIgnoreCase(((PlayerBean)bean).getName());
		}
		
	}
	
	
}
